package com.haoxuer.discover.area.rest.conver;

import com.haoxuer.discover.area.data.entity.Area;
import com.haoxuer.discover.area.rest.domain.response.simple.AreaDataSimple;
import com.haoxuer.discover.data.rest.core.Conver;
import com.haoxuer.discover.user.utils.ConverResourceUtils;

import java.util.ArrayList;

public class AreaDataSimpleConver implements Conver<AreaDataSimple, Area> {
  @Override
  public AreaDataSimple conver(Area source) {
    
    AreaDataSimple result = new AreaDataSimple();
    result.setId(source.getId());
    result.setPid(source.getParentId());
    result.setName(source.getName());
    result.setLat(source.getLat());
    result.setLng(source.getLng());
    if (source.getAreaType() != null) {
      result.setType(source.getAreaType().ordinal());
    }
    result.setCode(source.getCode());
    if (source.getChildrens() != null && source.getChildrens().size() > 0) {
      result.setChilds(ConverResourceUtils.coverCollect(source.getChildrens(), this));
    } else {
      result.setChilds(new ArrayList<AreaDataSimple>());
    }
    return result;
  }
}
